package com.palrevo.data.services;

import com.palrevo.data.dao.DAO;
import com.palrevo.data.dao.DAOFactory;
import com.palrevo.data.dao.DaoRecord;
import com.palrevo.data.dao.DataException;
import com.palrevo.data.models.AboutUs;
import com.palrevo.utils.Log;

/**
 * 
 * @author AAsha
 *
 */
public class CommonDBService extends ServiceBase {
	
	
	
	/**
	 * 
	 */
	private CommonDBService() {
	}

	/**
	 * 
	 * @author AAsha
	 * 
	 */
	private static class SingletonHolder {
		private static CommonDBService instance = new CommonDBService();
	}

	/**
	 * 
	 * @return CommonDBService instance
	 */
	public static CommonDBService getInstance() {
		return SingletonHolder.instance;
	}

	/**
	 * 
	 * @return AboutUs
	 * @throws DataException
	 */
	public AboutUs loadAboutUs() throws DataException{
		
		AboutUs aboutUs = null;
		
		try{
			
			DAO dao = DAOFactory.getInstance().createDao();
			
			//Load AboutUs
			String sql = "SELECT * FROM "+ Tables.about_us.name();
			dao.execute(sql);
			
			aboutUs = new AboutUs();;
			
			for(DaoRecord record:dao.getResult()){
				aboutUs.setId(Long.valueOf(record.getValue(Columns.ID.name()).toString()));
				aboutUs.setBody(record.getValue(Columns.BODY.name()).toString());
				aboutUs.setIcon(record.getValue(Columns.ICON.name()).toString());
			}
			
			
			
		}catch(Exception ex){
			Log.error(this, ex.getMessage());
			throw new DataException(ex.getMessage(), ex);
		}
		
		return aboutUs;
	}
}
